package com.leetcode.p100;

import com.bean.TreeNode;
import com.utils.TreeUtils;

/**
 * 深度
 */
public class Test129_bfs {

    public int sumNumbers(TreeNode root) {
        return bfs(root, 0);
    }

    private int bfs(TreeNode root, int preSum) {
        if (root == null) {
            return 0;
        }

        int sum = preSum * 10 + root.val;

        if (root.left == null && root.right == null) {
            return sum;
        } else {
            return bfs(root.left, sum) + bfs(root.right, sum);
        }
    }

    public static void main(String[] args) {
        TreeNode treeNode = TreeUtils.buildTree("1,2,3");

        Test129_bfs test = new Test129_bfs();
        int result = test.sumNumbers(treeNode);
        System.out.println(result);
    }

}
